import Vue from 'vue'
import VueRouter from 'vue-router'
import { login, ssoLogin, layout } from './commonRoute'

Vue.use(VueRouter)

let asyncRoutes = [
  login,
  ssoLogin,
  layout
]

const createRouter = () => new VueRouter({
  base: window.__POWERED_BY_QIANKUN__ ? '/' + window.appCode : '/',
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: asyncRoutes
})

const router = createRouter()

export function resetRouter (routes) {
  if (routes) {
    asyncRoutes = routes
  }
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
